package org.onionframework.servlet;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 
 * @author allan
 *
 */
public class ServletContexts {
	
	private static ThreadLocal<HttpServletRequest> requestHolder = new ThreadLocal<HttpServletRequest>();
	private static ThreadLocal<HttpServletResponse> responseHolder = new ThreadLocal<HttpServletResponse>();
	private static ServletContext servletContext;
	
	public static void setRequest(HttpServletRequest request){
		requestHolder.set(request);
	}
	
	public static void setResponse(HttpServletResponse response){
		responseHolder.set(response);
	}
	
	public static void setServletContext(ServletContext servletContext){
		ServletContexts.servletContext = servletContext;
	}
	
	public static HttpServletRequest getRequest(){
		return requestHolder.get();
	}
	
	public static HttpServletResponse getResponse(){
			return responseHolder.get();
	}
	
	public static HttpSession getSession(){
		return getRequest().getSession();
	}
	
	public static String getParameter(String name){
		return getRequest().getParameter(name);
	}
	
	public static ServletContext getServletContext(){
		return servletContext;
	}
}
